<%@ page import="com.rui1024.pojo.User" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>

<%
    if(request.getAttribute("user")==null){
        String username=null;
        String password=null;
        Cookie[] cookies = request.getCookies();
        for (int i = 0; cookies!=null && i<cookies.length ; i++) {
          if(cookies[i].getName().equals("userCookie")){
            username = cookies[i].getValue().split("-")[0];
            password = cookies[i].getValue().split("-")[1];
          }
        }
        if(username==null){
          username="";
        }
        if(password==null){
          password="";
        }
        pageContext.setAttribute("user",new User(username,password));
    }
%>

<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"><%--响应式开发--%>
<title>个人空间</title>
<link href="${pageContext.request.contextPath}/static/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/static/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/static/bootstrap/js/jQuery.js"></script>
<script src="${pageContext.request.contextPath}/static/bootstrap/js/bootstrap.js"></script>
<script src="${pageContext.request.contextPath}/static/js/jQuery.js"></script>

  <script>
      // function checkForm() {
      //   //js
      //   var username=document.getElementById("username").value;
      //   var password=document.getElementById("password").value;
      //
      //   if(username=="" || username==null){
      //     alert("请输入用户名！");
      //     return false
      //   }
      //   if(password=="" || password==null){
      //     alert("请输入密码！");
      //     return false
      //   }
      //   return true;
      // }
      //
      // window.onload=function(){
      //   document.getElementById("reset").onclick=function () {
      //     document.getElementById("username").value="";
      //     document.getElementById("password").value="";
      //   }
      // }
    
    //jquery
    function checkForm() {
      var username = $("#username").val();
      var password = $("#password").val();
      
      if(username=="" || username==null){
        alert("请输入用户名！");
        return false
      }
      if(password=="" || password==null){
        alert("请输入密码！");
        return false
      }
      return true;
    }
    
    $(function () {
      $("#reset").click(function () {
        $("#username").val("");
        $("#password").val("");
      })
    })


  </script>


<style type="text/css">
	  body {
        padding-top: 200px;
        padding-bottom: 40px;
        background-image: url('static/images/dog.gif');
      }
      
      .form-signin-heading{
      	text-align: center;
      }

      .form-signin {
        max-width: 300px;
        padding: 19px 29px 0px;
        margin: 0 auto 20px;
        background-color: #fff;
        border: 1px solid #e5e5e5;
        -webkit-border-radius: 5px;
           -moz-border-radius: 5px;
                border-radius: 5px;
        -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
           -moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
                box-shadow: 0 1px 2px rgba(0,0,0,.05);
      }
      .form-signin .form-signin-heading,
      .form-signin .checkbox {
        margin-bottom: 10px;
      }
      .form-signin input[type="text"],
      .form-signin input[type="password"] {
        font-size: 16px;
        height: auto;
        margin-bottom: 15px;
        padding: 7px 9px;
      }

</style>


</head>
<body>
<div class="container">
      <form name="myForm" class="form-signin" action="login" method="post" onsubmit="return checkForm()">
        <h2 class="form-signin-heading">个人空间管理系统</h2>
        <input id="username" name="username"   type="text" class="input-block-level" value="${user.username}" placeholder="用户名...">
        <input id="password" name="password"  type="password" class="input-block-level" value="${user.password}" placeholder="密码..." >
        <label class="checkbox">
          <input id="remember" name="remember" type="checkbox" value="remember-me">记住我 &nbsp;&nbsp;&nbsp;&nbsp;<span style="color:red">${errorMsg }</span>
        </label>
        <button class="btn btn-large btn-primary" type="submit">登录</button>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <button class="btn btn-large btn-primary" type="button" id="reset">重置</button>

        <p align="center" style="padding-top: 15px;">20应用3班  <a href="http://www.richard1024.com" target="_blank">http://www.richard1024.com</a></p>
      </form>
</div>
</body>
</html>